import axios from '@/libs/api.request'
import {getFullUrl} from '../config'

let getUrl = getFullUrl('user');

export const login = ({username, password}) => {
    const data = {
        username,
        password
    }
    return axios.request({
        url: getUrl('/system/login'),
        data,
        method: 'POST'
    })
}

export const getUserInfo = (token) => {
    /*  return axios.request({
        url: 'get_info',
        params: {
          token
        },
        method: 'get'
      })*/
    return new Promise(resolve => {
        let data = {
            code: 200,
            data: {
                avator: 'person',
                user_name: 'admin',
                user_id: 123,
                access: 'admin'
            },
            message: 'success'
        }
        resolve(data)
    })
}

//--------------------------------------GET

// 获取所有用户
export const listUser = () => {
    return axios.request({
        url: getUrl('/user'),
        method: 'GET'
    })
}


//--------------------------------------PATCH
// 更新备注
export const updateRemark = (user) => {
    return axios.request({
        url: getUrl('/user'),
        method: 'PATCH',
        data: {
            id: user.id,
            remark: user.remark
        }
    })
}

// 更新用户
export const updateUser = (user) => {
    return axios.request({
        url: getUrl('/user'),
        method: 'PUT',
        data: user
    })
}

//--------------------------------------DELETE
// 删除用户
export const removeUser = (userId) => {
    return axios.request({
        url: getUrl('/user/' + userId),
        method: 'DELETE'
    })
}


//--------------------------------------POST
// 添加用户
export const addUser = (user) => {
    return axios.request({
        url: getUrl('/user'),
        method: 'POST',
        data: user
    })
}
